<template>
    <div class="user clearfix">

    <div class="d-a-c lh30 ww100 pt16">
      
      <div class="flex-1 tc">
        <p>营业额（元）</p>
        <p class="f20 fb gray3">{{total_price}}</p>
      </div>
      <div class="flex-1 tc">
        <p>支付费率(0.6%;元)</p>
        <p class="f20 fb gray3">{{fee}}</p>
      </div>
      
      <div class="flex-1 tc">
        <p>分佣总额（元）</p>
        <p class="f20 fb gray3">{{total_commission}}</p>
      </div>
      
      
      <div class="flex-1 tc">
        <p>累计收入(元)</p>
        <p class="f20 fb gray3">{{income_money}}</p>
      
      </div>
      
      

      <div class="flex-1 tc">
        <p>可提现(元;T+3)</p>
        <p class="f20 fb gray3">{{withdrawal_money}}</p>
      </div>
    
    </div>

  
      <div class="common-seach-wrap">
       
          <el-form size="small" :inline="true" :model="searchForm" class="demo-form-inline">
          <el-form-item label="">
            <el-input size="small" v-model="searchForm.order_no" placeholder="请输入订单号"></el-input>
          </el-form-item>
        
          <el-form-item label="">
            <div class="block">
              <span class="demonstration"></span>
              <el-date-picker
                size="small"
                v-model="searchForm.create_time"
                type="daterange"
                value-format="yyyy-MM-dd"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </div>
          </el-form-item>
          <el-form-item>
          <el-button size="small" type="success" @click="onExport">导出</el-button>
          </el-form-item>
          <el-form-item>
            <el-button size="small" type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
          </el-form-item>



          <el-form-item>
                  <el-button size="small" type="primary"  @click="clickWithdrawal">提现</el-button>
          </el-form-item>

          <el-form-item>
                  <el-button size="small" type="primary"  @click="getWithdrawal()">提现记录</el-button>
          </el-form-item>

          <p>
            <span v-for="item in date_list">
              <el-form-item>
                    <el-button size="small" type="primary"  @click="clickDate(item.date_time)">{{ item.date_time_text }}</el-button>
              </el-form-item>
           </span>
          
        </p>

        </el-form>
      </div>
      <div class="table-wrap">
      
        <el-table size="small" :data="tableData.data" :span-method="arraySpanMethod" border style="width: 100%" v-loading="loading">
          <el-table-column prop="order_no" label="订单信息" width="400">
            <template slot-scope="scope">
              <div class="order-code" v-if="scope.row.is_top_row">
                <span class="state-text"
                      :class="{'state-text-red':scope.row.order_source != 10}">{{ scope.row.order_source_text }}</span>
                <span v-if="scope.row.is_first_order" class="state-text state-text-red">首单</span> 
                <span class="c_main">订单号：{{ scope.row.order_no }}</span>
                <span class="pl16">下单时间：{{ scope.row.order_create_time_text }}</span>
              
              </div>
              <template v-else>
                <div class="product-info" v-for="(item, index) in scope.row.product" :key="index">
                  <div class="pic"><img v-img-url="item.image.file_path" alt=""/></div>
                  <div class="info">
                    <div class="name gray3 product-name">
                      <span>{{ item.product_name }}</span>
                    </div>
                    <!-- <div class="gray9" v-if="item.product_attr">{{ item.product_attr }}</div> -->
                    <div class="gray9">分佣比例：{{ item.commission_rate }}%</div>
                    <div class="gray9">佣金：{{ item.commission_money }}</div>
                  </div>
                  <div class="d-c-c d-c">
                    <div class="orange">￥ {{ item.product_price }}</div>
                    <div class="gray3">数量 x{{ item.total_num }}</div>
                  </div>
                </div>
              </template>

              
            </template>
          </el-table-column>

          <el-table-column prop="total_price" label="订单总额">
            <template slot-scope="scope">
              <div class="orange">{{ scope.row.total_price }}</div>
            </template>
          </el-table-column>
          
          <el-table-column prop="system_coupons.reduce_price" label="优惠券抵扣"></el-table-column>

          <el-table-column prop="pay_price" label="实付金额">
            <template slot-scope="scope">
              <div class="orange">{{ scope.row.pay_price }}</div>
            
            </template>
          </el-table-column>

          <el-table-column prop="pay_price" label="佣金">
            <template slot-scope="scope">
              <div class="orange">{{ scope.row.commission }}</div>
            </template>
          </el-table-column>

          <el-table-column prop="fee" label="支付费率(0.6%;元)">
            <template slot-scope="scope">
              <div class="orange">{{ scope.row.fee }}</div>
            
            </template>
          </el-table-column>

          <el-table-column prop="pay_price" label="退款">
            <template slot-scope="scope">
              <div class="orange">{{ scope.row.refund_money }}</div>
              
            </template>
          </el-table-column>

          <el-table-column prop="" label="买家">
            <template slot-scope="scope" v-if="!scope.row.is_top_row && scope.row.user">
              <div>{{ scope.row.user.nickName }}</div>
              <div class="gray9">ID：({{ scope.row.user.user_id }})</div>
            </template>
          </el-table-column>
          
       
        </el-table>
      </div>

      <!--分页-->
      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          :current-page="curPage"
          :page-size="pageSize"
          layout="total, prev, pager, next, jumper"
          :total="totalDataNumber"
        ></el-pagination>
      </div>
      
      

      <Withdrawal :open_withdrawal.sync="open_withdrawal"   :shop_id="shop_id" :random="random"></Withdrawal>

      <el-dialog
        title="提现"
        :visible.sync="dialogVisible"
        width="25%"
        :before-close="handleClose"  append-to-body style="z-index: 3000;">
        <p><el-input size="small" v-model="withdrawalForm.money" placeholder="请输入提现金额"></el-input></p>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="submitWithdrawal">确 定</el-button>
        </span>
        </el-dialog>

  </div>

 
</template>
<script>

import StatisticsApi from "@/api/statistics.js";
import Withdrawal from "./part/Withdrawal.vue";
import qs from 'qs';
export default {
  components:{
    Withdrawal
  },
  data() {
    return {
      activeName: 'all',
      drawer_open: false,
      /*是否加载完成*/
      loading: true,
      /*列表数据*/
      tableData: [],
      /*一页多少条*/
      pageSize: 20,
      /*一共多少条数据*/
      totalDataNumber: 0,
      /*当前是第几页*/
      curPage: 1,
      searchForm: {
        search: '',
        order_no: '',
        style_id: '',
        create_time: ''
      },
   
   
      total_price:0,
      total_commission:0,
      fee:0,
      withdrawal_money:0,
      income_money:0,
      shop_supplier_id:0,
    
      open_withdrawal :false,
      date_list:[],
      shop_id:0,
      random:0,
      dialogVisible:false,
      withdrawalForm:{
        money:'',
      },
    }
  },


created() {
  this.getDateList()
  this.getData()
},
  methods: {
    
    onExport: function () {
      let baseUrl =
        process.env.NODE_ENV === "development"
          ? window.location.protocol + "//" + window.location.host
          : process.env.VUE_APP_API_URL;
      window.location.href = baseUrl + '/index.php/supplier/statistics.supplier/exportCommission?' + qs.stringify(this.searchForm);
    },
    submitWithdrawal() {

      let Params = this.withdrawalForm;

  
      StatisticsApi.withdrawal(Params, true)
        .then(res => {
          this.$message({
                    message: res.msg,
                    type: 'success'
                  });

          this.withdrawalForm.money = '';
          this.dialogVisible = false;
          this.getData();
          this.random = new Date().getTime();
        })
        .catch(error => {
        });

    },

    handleClose(done) {
      this.dialogVisible = false;
    },

    clickWithdrawal(){
      this.dialogVisible = true;
    },

    getDateList(){
      let Params = [];
      StatisticsApi.getDateList(Params, true)
        .then(res => {
            this.date_list = res.data.list
        })
        .catch(error => {
        });
   
    },
    clickDate(dates){
      this.searchForm.create_time = dates;
      this.getData();
    },


    /*跨多列*/
    arraySpanMethod(row) {
      if (row.rowIndex % 2 == 0) {
        if (row.columnIndex === 0) {
          return [1, 8];
        }
      }
    },
    /*选择第几页*/
    handleCurrentChange(val) {
      let self = this;
      self.curPage = val;
      self.getData();
    },

    /*每页多少条*/
    handleSizeChange(val) {
      this.curPage = 1;
      this.pageSize = val;
      this.getData();
    },

    
    getData() {
      let self = this;
      let Params = this.searchForm;
    
      Params.shop_supplier_id = 0;
    
      Params.page = self.curPage;
      Params.list_rows = self.pageSize;
      self.loading = true;
      StatisticsApi.getSupplierCommissionList(Params, true)
        .then(res => {
          let list = [];
          this.total_commission = res.data.data.total_commission
          this.fee = res.data.data.fee
          this.withdrawal_money = res.data.data.withdrawal_money
          this.income_money = res.data.data.income_money
          this.total_price = res.data.data.total_price
          this.shop_supplier_id = res.data.data.shop_supplier_id
          for (let i = 0; i < res.data.data.list.data.length; i++) {
            let item = res.data.data.list.data[i];
            let topitem = {
              order_no: item.order_no,
              order_create_time_text: item.order_create_time_text,
              order_source: item.order_source,
              order_source_text: item.order_source_text,
              is_top_row: true,
             
              is_first_order: item.is_first_order,
            };
            list.push(topitem);
            list.push(item);
          }
          console.log('数据',list)
          self.tableData.data = list;

          self.totalDataNumber = res.data.data.list.total;
          // self.exStyle = res.data.ex_style;
          
          // self.order_count = res.data.order_count.order_count;
          self.loading = false;
        })
        .catch(error => {
        });
    },
    /*搜索查询*/
    onSubmit() {
      this.curPage = 1;
      this.tableData = [];
      this.getData();
    },

   
    /*切换菜单*/
    handleClick(tab, event) {
      let self = this;
      self.curPage = 1;
      self.getData();
    },
    getWithdrawal() {
      this.random = new Date().getTime();
      this.shop_id = this.shop_supplier_id;
      this.open_withdrawal = true;
      
    },

  }
}

</script>
<style scoped>
.user {
  padding: 20px;
  padding-top: 0;
}
.withdrawal {
  padding: 20px;
  padding-top: 0;
}
.order-code .state-text {
  padding: 2px 4px;
  border-radius: 4px;
  background: #808080;
  color: #ffffff;
}
.order-code .state-text-red {
  background: red;
}
</style>
